import { AssetManager, assetManager } from "cc";
import { Logger } from "./Logger";

export class BundleManager {

    public static instance: BundleManager = new BundleManager();

    
    public bundleName_main: string = "main"
    // public bundleName_child: string = "child"

    public bundleNameList: Array<string> = [
      
    ]

    public bundleMap: Map<string, AssetManager.Bundle> = new Map<string, AssetManager.Bundle>()

    public loadBundle(bundleName: string): Promise<void> {
        Logger.log("loadBundle=====", bundleName)
        return new Promise((resolve, reject) => {
            assetManager.loadBundle(bundleName, (err: Error, bundle: AssetManager.Bundle) => {
                Logger.log("loadBundle==complete===", err, bundle)
                if (err) {
                    reject()
                } else {
                    this.bundleMap.set(bundleName, bundle);
                    resolve();
                }
            });
        })
    }
}